package com.cn.web.role.service.impl;

import com.cn.role.RoleMenuDO;
import com.cn.util.SnowflakeIdWorkerUtil;
import com.cn.web.role.mapper.IRoleMenuMapper;
import com.cn.web.role.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description: RoleMenuService <br>
 * date: 21.12.16 13:50 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@Service
public class RoleMenuServiceImpl implements RoleMenuService {

    @Autowired
    private IRoleMenuMapper roleMenuMapper;

    @Override
    public int del(String roleId) {
        Map<String, Object> pd = new HashMap<>();
        pd.put("role_id", roleId);
        return this.roleMenuMapper.deleteByMap(pd);
    }

    @Override
    public void add(RoleMenuDO roleMenuEntity) {
        roleMenuEntity.setId(SnowflakeIdWorkerUtil.getId());
        this.roleMenuMapper.insert(roleMenuEntity);
    }

    @Override
    public List<RoleMenuDO> list(String roleId) {
        Map<String, Object> pd = new HashMap<>();
        pd.put("role_id", roleId);
        List<RoleMenuDO> list = this.roleMenuMapper.selectByMap(pd);
        for (RoleMenuDO entity : list) {
            entity.setButtonArray();
        }
        return list;
    }

}